
(function ($) {
	$.fn.sharing = function() {
		$parent = $(this);
		$input = $('#r-input');
		$submit = $('#r-submit');
		signup = new XMLHttpRequest();
		share =  new XMLHttpRequest();
		contact =  new XMLHttpRequest();
		signup.onreadystatechange = function() {
			if (signup.readyState==3 || signup.readyState==2 || signup.readyState==1) {
				
				}
			if(signup.readyState==4 && signup.status == 200) {
				if(signup.responseText == "SentSent") {
					$parent.find('#register-form-content').hide();
					$parent.find('#share-form-content').show();
				}
				
			
			}
		}
			
		share.onreadystatechange = function() {
			if (share.readyState==3 || share.readyState==2 || share.readyState==1) {
				
				}
			if(share.readyState==4 && share.status == 200) {
				if(share.responseText == "SentSent") {
					$parent.find('#share-form-content').find('h1').text("Thank you for refering us!");
					$parent.find('#share-form-content').find('#s-input').val('');
				}
		
		}
		
		}
		
		contact.onreadystatechange = function() {
			if (contact.readyState==3 || contact.readyState==2 || contact.readyState==1) {
				
				}
			if(contact.readyState==4 && contact.status == 200) {
				
				alert(contact.responseText);
		
		}
		
		}
			
		
			$('#register-form').submit(function() {
				signup.open('post','beta-signup.php', true);
				signup.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				var serializedData = $(this).serialize();	
				signup.send(serializedData);	
				return false;
				
			});
			
			$('#share-form').submit(function() {
				share.open('post','beta-referal.php', true);
				share.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				var serializedData = $(this).serialize();	
				share.send(serializedData);	
				return false;
				
			});
			
			$('#contact').submit(function() {
				contact.open('post','contact.php', true);
				contact.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				var serializedData = $(this).serialize();	
				contact.send(serializedData);	
				return false;
				
			});
		
		
	
	
	};






})(jQuery);